package com.yaofeng.mybatis.config;

import com.yaofeng.mybatis.filter.XssFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.MapUtils;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * Created by yaofeng on 2019/8/19.
 */
@Configuration
@Slf4j
public class XssConfig {

    public XssConfig() {
        log.info("====================XssConfig容器启动初始化=============");
    }
    /**
     * xss过滤拦截器
     */
    @Bean
    public FilterRegistrationBean xssFilterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new XssFilter());
        filterRegistrationBean.setOrder(1);
        filterRegistrationBean.setEnabled(true);
        filterRegistrationBean.addUrlPatterns("/*");
        //  xss过滤拦截器 初始化配置
        Map<String, String> initParameters = new HashMap<>();
        // 配置不过滤地址
        initParameters.put("excludes", "/favicon.ico,/img/*,/js/*,/css/*");
        // 配置富文本是否也过滤
        initParameters.put("isIncludeRichText", "true");
        filterRegistrationBean.setInitParameters(initParameters);
        return filterRegistrationBean;
    }


}
